package com.cc.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("test")
@Slf4j
public class TestController {

    @RequestMapping("index")
    public String index() {
        System.out.println("请求test/index请求");
        //index视图 名字(jsp的名字)
        //视图前缀+ index(视图) + 视图后缀=/WEB-INF/jsp/index.jsp
        return "index";
    }

    @Resource
    HttpServletRequest request1;
    @Resource
    HttpSession session1;
    @Resource
    ServletContext application1;

    //五、默认参数
    @RequestMapping("/test")
    public String testParam(HttpServletRequest request2 ,@CookieValue("JSESSIONID") String value) {
        //1.request
        log.debug("request1==>" + request1);
        log.debug("request2==>" + request2);
        //2.session
        log.error("session===>" + request1.getSession());
        log.error("session1===>" + session1);
        //3.application
        log.debug("application1====>" + application1);
        log.debug("application===>" + request1.getServletContext());
        //4.cookie
        log.debug("cookie====>"+value);
        return "index";
    }
}